package com.zhw.controller;

import com.zhw.pojo.Result;
import com.zhw.pojo.entry.CustomerLinkMan;
import com.zhw.pojo.vo.LinkManVO;
import com.zhw.service.LinkService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("linkMan")
@Slf4j
public class LinkManController {

    @Autowired
    LinkService linkService;

    @GetMapping("getLinkMan")
    public Result getLinkMan(CustomerLinkMan customerLinkMan){
        log.info("查看联系人数据：{}",customerLinkMan);
        List<LinkManVO> list=linkService.getLinkMan(customerLinkMan);
        return Result.success(list);
    }



    @GetMapping("getLinkManById")
    public Result getLinkManByID(Integer id){
        log.info("查询当前联系人：{}",id);
        CustomerLinkMan customerLinkMan=linkService.getLinkManByID(id);
        return Result.success(customerLinkMan);
    }


    @PostMapping("save")
    public Result save(@RequestBody CustomerLinkMan customerLinkMan){
        log.info("添加客户联系人信息：{}",customerLinkMan);
        linkService.save(customerLinkMan);
        return Result.success();
    }

    @PutMapping("update")
    public Result update(@RequestBody CustomerLinkMan customerLinkMan){
        log.info("修改客户联系人信息：{}",customerLinkMan);
        linkService.update(customerLinkMan);
        return Result.success();
    }


    @DeleteMapping("{id}")
    public Result deleteByID(@PathVariable Integer id){
        log.info("删除一个客户的联系方式：{}",id);
        linkService.deleteById(id);
        return Result.success();
    }
}
